package com.k2data.k2app.controller;

import com.k2data.k2app.response.CommonResultResponse;
import com.k2data.k2app.response.ResponseHelper;
import com.k2data.k2app.service.WechatInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;

/**
 * 系统用户
 * Created by clb on 17-3-17.
 */
@Api(description = "微信操作")
@RestController
@RequestMapping("/wechats")
public class WechatController {
	@Autowired
	private WechatInfoService wechatInfoService;



    @ApiOperation(value = "是否绑定了微信")
    @GetMapping(value = "/isband")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "code", dataType = "String", paramType = "query")
    })
    public ResponseEntity<CommonResultResponse> isband(
            @RequestParam(value = "code") @NotNull String code
    ) throws Exception {
        return ResponseHelper.success(wechatInfoService.isBand(code));
    }

	@ApiOperation(value = "绑定")
	@GetMapping(value = "/band")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "userId", value = "userId", dataType = "Long", paramType = "query"),
			@ApiImplicitParam(name = "code", value = "code", dataType = "String", paramType = "query")
	})
	public ResponseEntity<CommonResultResponse> user(
			@RequestParam(value = "userId") @NotNull Long userId,
			@RequestParam(value = "code")  @NotNull String code
	) throws Exception {
		return ResponseHelper.success(wechatInfoService.insert(userId,code));
	}

	@ApiOperation(value = "取消绑定")
	@GetMapping(value = "/cancelBand")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "code", value = "code", dataType = "String", paramType = "query")
	})
	public ResponseEntity<CommonResultResponse> cancelBand(
			@RequestParam(value = "code")  @NotNull String code
	) throws Exception {
		return ResponseHelper.success(wechatInfoService.delete(code));
	}
}
